package ad_exercise_3.model;

import java.util.Iterator;

import ad_exercise_3.controller.Game;
import ad_exercise_3.model.Card.CardColour;

/**
 * Represents a player controller by the computer. Currently it's playing strategy is quite stupid...
 * 
 * @author Karen Berntsen (s0815799)
 * @author Erik Stens (s0615374)
 */
public class ComputerPlayer extends Player {
	
	public ComputerPlayer(CustomList<Card> initialHand, Game game) {
		super(initialHand, game);
	}
	
	public ComputerPlayer(String name, CustomList<Card> initialHand, Game game) {
		super(name, initialHand, game);
	}
	
	@Override
	protected Card askCard() {
		return takeBestCard();
	}
	
	private Card takeBestCard() {
		Iterator<Card> handIterator = hand.iterator();
		Card card;
		while (handIterator.hasNext()) {
			card = handIterator.next();
			if (game.cardFits(card)) {
				handIterator.remove();
				return card;
			}
		}
		return null;
	}
	
	@Override
	protected boolean keepCard(Card card) {
		return false;
	}
	
	@Override
	public CardColour askColour() {
		for (Card card : hand) {
			if (card.getCardColour() != CardColour.UNKNOWN) {
				return card.getCardColour();
			}
		}
		
		return Card.getRandomCardColour();
	}
	
	@Override
	public String getType() {
		return "computer";
	}
}
